﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExpressionUtil.Common
{
    /// <summary>
    /// 数学助手类
    /// </summary>
    internal static class MathHelper
    {
        /// <summary>
        /// 默认的数字精度
        /// </summary>
        public const decimal COMPARE_PRECISION_DEFAULT = 0.000001m;

        /// <summary>
        /// 按指定精度比较两个数是否相等
        /// </summary>
        /// <param name="num1">数字1</param>
        /// <param name="num2">数字2</param>
        /// <param name="precision">比较的精度</param>
        /// <returns>是否相等</returns>
        public static bool Equal(decimal num1, decimal num2, decimal precision)
        {
            return Math.Abs(num1 - num2) <= precision;
        }

        /// <summary>
        /// 按指定精度比较两个数是否相等
        /// </summary>
        /// <param name="num1">数字1</param>
        /// <param name="num2">数字2</param>
        /// <param name="precision">比较的精度</param>
        /// <returns>是否相等</returns>
        public static bool Equal(float num1, float num2, float precision)
        {
            return Math.Abs(num1 - num2) <= precision;
        }
    }
}
